package birdsong.server;

import java.util.LinkedList;

public class ServerClient {


	private String nickName;

	private LinkedList<ServerClient> followers;


	/**
	 * Constructor to the server client
	 * @param nickName The nickname to the client
	 */
	public ServerClient(String nickName) {


		this.nickName=nickName;

		followers= new LinkedList<ServerClient>();

	}

	/**
	 * Adds a follower to the list of followers
	 * @param client Server client to add to followers list
	 */
	public void addFollower(ServerClient client){

		followers.add(client);

	}

	/**
	 * Removes a server client from the followers list
	 * @param client Server client to remove from the followers list
	 */
	public void removeFollower(ServerClient client){
		if(!followers.isEmpty())
			followers.remove(client);
	}


	/**
	 * Return the list of followers from this client
	 * @return
	 */
	public LinkedList<ServerClient> getFollowers() {
		return followers;
	}


	/**
	 * Return the nickname of this client
	 * @return
	 */
	public String getNickName() {

		return nickName;
	}

	@Override
	public String toString() {
		return "ServerClient [nickName=" + nickName + ", followers="
		+ followers()+ "]";
	}


	/**
	 * Creates a string with the current followers of this client
	 * @return
	 */
	private String followers() {
		String stringOfCurrentFollowers = "";

		for (ServerClient client : followers) {
			stringOfCurrentFollowers+=client.getNickName()+", ";
		}
		return stringOfCurrentFollowers;
	}


}
